namespace SpaceMutinyNameGenerator
{
	using System;
	using System.Collections.Generic;

	using PugLib.Math;

	public sealed class NameList
	{
		private readonly List<String> _nameList;

		public NameList()
		{
			_nameList = new List<String>();
		}

		public NameList(IEnumerable<String> initialNames)
		{
			_nameList = new List<String>(initialNames);
		}

		public String this[Int32 index]
		{
			get { return _nameList[index]; }
			set { _nameList[index] = value; }
		}

		public Int32 Count
		{
			get { return _nameList.Count; }
		}

		public void Add(String name)
		{
			_nameList.Add(name);
		}

		public void Clear()
		{
			_nameList.Clear();
		}

		public void ForEach(Action<String> action)
		{
			_nameList.ForEach(action);
		}

		private void RemoveAt(Int32 index)
		{
			_nameList.RemoveAt(index);
		}

		private void Insert(Int32 index, String item)
		{
			_nameList.Insert(index, item);
		}

		public void Randomize()
		{
			Int32 count = this.Count;
			for (Int32 i = 0; i < count; i++)
			{
				String tmp = this[i];
				this.RemoveAt(i);
				this.Insert(PugRandom.GetRandomInRange(0, count), tmp);
			}
		}

		internal Boolean Contains(String item)
		{
			return _nameList.Contains(item);
		}

		internal IList<String> AsList()
		{
			return _nameList;
		}
	}
}